import { deleteByPrimaryKeyForProTables, selectByPrimaryKeyForProTables, insertForProTables, updateForProTables, deleteByMapForProTables,updateByMapForProTables, getOneForProTables,getAllForProTables,queryPageForProTables, countForProTables, insertBatchForProTables, deleteBatchForProTables,updateBatchForProTables } from '@/services/system/api_protables';

export default {
    namespace: 'protables',

    state: {
        data: {
            list: [],
            pagination: {},
        },
    },

    effects: {
            *delete_by_primarykey_for_protables({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProTables, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProTables',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });


            },
            *select_by_primarykey_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProTables, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProTables',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(insertForProTables, payload);
                yield put({
                    type: 'insertForProTables',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(updateForProTables, payload);
                yield put({
                    type: 'updateForProTables',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *delete_by_map_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProTables, payload);
                yield put({
                    type: 'deleteByMapForProTables',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProTables, payload);
                yield put({
                    type: 'updateByMapForProTables',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProTables, payload);
                yield put({
                    type: 'getOneForProTables',
                    payload: response,
                });

                if (callback) callback();
            },
            *get_all_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProTables, payload);
                yield put({
                    type: 'getAllForProTables',
                    payload: response,
                });

                if (callback) callback();
            },
            *query_page_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProTables, payload);
                yield put({
                    type: 'queryPageForProTables',
                    payload: response,
                });

                if (callback) callback();
            },
            *count_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(countForProTables, payload);
                yield put({
                    type: 'countForProTables',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProTables, payload);
                yield put({
                    type: 'insertBatchForProTables',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProTables, payload);
                yield put({
                    type: 'deleteBatchForProTables',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_protables({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProTables, payload);
                yield put({
                    type: 'updateBatchForProTables',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProTables, {});
                yield put({
                type: 'queryPageForProTables',
                payload: responsedata,
                });

                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProTables(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
    },
};
